﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sharp.Portal.ExtNet.FormField
{
    /// <summary>
    /// 主数据字段
    /// </summary>
    public class MasterDataField : ElementField
    {
        /// <summary>
        /// 主数据字段
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="masterDataCategory"></param>
        public MasterDataField(string fieldName, string masterDataCategory)
        {
            this.FieldName = fieldName;
            this.MasterDataCategory = masterDataCategory;
        }
        /// <summary>
        /// 主数据分类
        /// </summary>
        public string MasterDataCategory { get; }
        /// <summary>
        /// 生成
        /// </summary>
        /// <param name="nonFirst"></param>
        /// <returns></returns>
        public override string Build(bool nonFirst = false)
        {
            if (this.IsBrowsing() && !this.KeepingXType)
            {
                return $"x.DisplayFieldFor(m => m.{this.FieldName}).Code2Text(\"{MasterDataCategory}\",Model.{this.FieldName})" + base.Build(nonFirst);
            }
            AddFieldProperty("Editable", false);
            AddFieldProperty("MultiSelect", false);

            return string.Format("x.ComboBoxFor(m => m.{0}).MasterData(\"{1}\",Model.{0})",
                       this.FieldName, MasterDataCategory) + base.Build(nonFirst);
        }
    }
}